package net.lanelife.casino.caipiao.dto.admin;

import java.util.List;

import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Root;
import javax.persistence.criteria.Selection;

import net.lanelife.casino.caipiao.entity.RechargeRecord;
import net.lanelife.casino.caipiao.entity.RechargeRecord_;
import net.lanelife.casino.common.dto.support.GenericTable;
import net.lanelife.casino.common.entity.json.serialize.CurrencySerializer;

import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.google.common.collect.Lists;

/**
 * @author Lane
 * 
 * 充值记录表格
 *
 * @param <DTO>
 */
public class RechargeRecordTable<DTO> extends GenericTable<DTO, RechargeRecord> {

	private static final long serialVersionUID = -5094072656084867697L;

	@JsonSerialize(using = CurrencySerializer.class)
	private Double amountOnlinePayment = 0D;
	@JsonSerialize(using = CurrencySerializer.class)
	private Double feeOnlinePayment = 0D;
	
	@JsonSerialize(using = CurrencySerializer.class)
	private Double amountBankTransfer = 0D;
	@JsonSerialize(using = CurrencySerializer.class)
	private Double feeBankTransfer = 0D;

	public RechargeRecordTable() {}

	public RechargeRecordTable(Double amountOnlinePayment,
			Double feeOnlinePayment, Double amountBankTransfer,
			Double feeBankTransfer) {
		super();
		this.amountOnlinePayment = amountOnlinePayment;
		this.feeOnlinePayment = feeOnlinePayment;
		this.amountBankTransfer = amountBankTransfer;
		this.feeBankTransfer = feeBankTransfer;
	}

	@Override
	public List<Selection<?>> buildExpression(Root<RechargeRecord> root, CriteriaQuery<?> query, CriteriaBuilder builder) {
		List<Selection<?>> columns = Lists.newArrayList();
		columns.add(builder.sum(builder.<Double>selectCase().when(builder.equal(root.get(RechargeRecord_.way), RechargeRecord.Way.OP), root.<Double>get(RechargeRecord_.amount)).otherwise(0D)));
		columns.add(builder.sum(builder.<Double>selectCase().when(builder.equal(root.get(RechargeRecord_.way), RechargeRecord.Way.OP), root.<Double>get(RechargeRecord_.fee)).otherwise(0D)));
		columns.add(builder.sum(builder.<Double>selectCase().when(builder.equal(root.get(RechargeRecord_.way), RechargeRecord.Way.BT), root.<Double>get(RechargeRecord_.amount)).otherwise(0D)));
		columns.add(builder.sum(builder.<Double>selectCase().when(builder.equal(root.get(RechargeRecord_.way), RechargeRecord.Way.BT), root.<Double>get(RechargeRecord_.fee)).otherwise(0D)));
		return columns;
	}



}
